﻿using System.Diagnostics;
using dm;

using static System.Net.Mime.MediaTypeNames;

//注册大漠
var regCom = AutoRegCom("regsvr32 -s dm.dll");
if (!string.IsNullOrWhiteSpace(regCom))
{
    Console.WriteLine("注册dm失败！");
}

//实例化dm对象
dmsoft dm = new dmsoft();
Console.WriteLine($"大漠插件{dm.Ver()}");
// 收费注册
var regCharge = dm.Reg(DmConfig.DmRegCode, DmConfig.DmVerInfo);
Console.WriteLine($"收费注册返回：{regCharge}");
if (regCharge != 1)
{
    throw new Exception("收费注册失败");
}

int hwnd = dm.FindWindow("WeChatMainWndForPC", "微信");//获取标题为“GaugeStudio”的窗体句柄
int bind  = dm.BindWindow(hwnd, "dx2", "windows3", "windows", 0);
dm.MoveTo(130, 130);//鼠标移动到GaugeStudio窗体的30，30位置
dm.LeftClick();//鼠标单击左键
Console.ReadKey();

static string AutoRegCom(string strCmd)
{
    string rInfo;
    try
    {
        Process myProcess = new Process();
        ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd.exe");
        myProcessStartInfo.UseShellExecute = false;
        myProcessStartInfo.CreateNoWindow = true;
        myProcessStartInfo.RedirectStandardOutput = true;
        myProcess.StartInfo = myProcessStartInfo;
        myProcessStartInfo.Arguments = "/c " + strCmd;
        myProcess.Start();
        StreamReader myStreamReader = myProcess.StandardOutput;
        rInfo = myStreamReader.ReadToEnd();
        myProcess.Close();
        return rInfo;
    }
    catch (Exception ex)
    {
        return ex.Message;
    }
}